package com.rabbitmq.receivers.dlx;

import com.rabbitmq.client.Channel;
import com.rabbitmq.config.dlx.DLXConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author 王霄
 * @date 2022/1/8 21:09
 */
@Component
@Slf4j
public class DLXReceiver {

    @RabbitListener(queues = DLXConfig.DLX_QUEUE)
    public void consume1(String orderId, Message message, Channel channel) throws IOException {
        channel.basicReject(message.getMessageProperties().getDeliveryTag(), false);
        log.info("订单消息被拒,orderId: {}", orderId);
    }

    @RabbitListener(queues = DLXConfig.ORDER_QUEUE)
    public void consume2(String orderId) {
        log.info("订单60秒未支付,已取消,orderId: {}", orderId);
    }

}
